<%@ Register TagPrefix="freak" Namespace="freak" Assembly = "fricchettone"%>
<%@ Page Language="C#" Description="Homepage" debug="false" trace="true" Culture="it-IT" EnableViewState="false"%>
<%@ Import Namespace="Google.GData.Apps"%>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" Content="text/html; charset=ISO-8859-1">
<title id="title" runat=server></title>
</head>
<script language="C#" runat=server>
void Page_Load(Object sender, EventArgs EvArgs) {

    AppsService service = new AppsService(domain, userName, password);

    Trace.Write("Request.Form.Get(\"tohash\"):" + Request.Form.Get("tohash"));
    Trace.Write("Request.Form.Count():" + Request.Form.Count);
    
    if( Request.Form.Get("tohash") != null ) {
        // hash and encode in UTF8
        System.Security.Cryptography.MD5CryptoServiceProvider md5Hasher = new System.Security.Cryptography.MD5CryptoServiceProvider();
        byte[] hashedBytes;
        UTF8Encoding encoder = new UTF8Encoding();
        hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(Request.Form.Get("tohash")));
        string hashString = "";

        for (int i = 0; i < hashedBytes.Length; i++)
        {
            hashString += Convert.ToString(hashedBytes[i], 16).PadLeft(2, '0');
        }

        outnet.InnerHtml = "dotnet md5 hashed: "+hashString;

        // hash PHP style
        System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5CryptoServiceProvider.Create();
        byte[] dataMd5 = md5.ComputeHash(Encoding.Default.GetBytes( Request.Form.Get("tohash") ));
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < dataMd5.Length; i++)
            sb.AppendFormat("{0:x2}", dataMd5[i]);
        outphp.InnerHtml = "php md5 hashed: " + sb.ToString(); 
    }
        
}
</script>
<body class="body" id="body" runat="server">

<form action="" method="post">
<input type="text" name="tohash" id="tohash"/>
<input type="submit" value="hasha" />
</form>

<span id="outnet" runat="server"/>
<br />
<span id="outphp" runat="server"/>

</body>
</html>